package com.water.dmdb.db;

import com.water.dmdb.util.DbUtil;
import org.apache.poi.hssf.usermodel.*;

import java.io.File;
import java.io.FileInputStream;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

public class LoadExcel {

    /**
     * @param sheet
     * @param column
     **/
    public void loadEXCEL(int sheet, int column) {

    }

    public static void main(String[] args) throws Exception {
        //DDF SQL覆盖度测试_v2.0.xls
        File file = new File("C:/Users/shisheng/Desktop/SQL覆盖度测试_v2.0.xls");
        FileInputStream inp = new FileInputStream(file);
        HSSFWorkbook wb = new HSSFWorkbook(inp);
        //获得总列数
        String sheetName = "已验证_函数";
        HSSFSheet sheet = wb.getSheet(sheetName);
        int totalRows = sheet.getPhysicalNumberOfRows();
        for (int i = 1; i <= totalRows; i++) {
            HSSFCell cell = sheet.getRow(i).getCell(1);
            String cellValue;
            switch (cell.getCellType()) {
                case HSSFCell.CELL_TYPE_NUMERIC: // 数字
                    cellValue = cell.getNumericCellValue() + "";
                    break;

                case HSSFCell.CELL_TYPE_STRING: // 字符串
                    cellValue = cell.getStringCellValue();
                    break;

                case HSSFCell.CELL_TYPE_BOOLEAN: // Boolean
                    cellValue = cell.getBooleanCellValue() + "";
                    break;

                case HSSFCell.CELL_TYPE_FORMULA: // 公式
                    cellValue = cell.getCellFormula() + "";
                    break;

                case HSSFCell.CELL_TYPE_BLANK: // 空值
                    cellValue = "";
                    break;

                case HSSFCell.CELL_TYPE_ERROR: // 故障
                    cellValue = "非法字符";
                    break;

                default:
                    cellValue = "未知类型";
                    break;
            }
            System.out.println(cellValue);
            if (cellValue != null && !cellValue.equals("")) {
                try {
                    List<Map<String, Object>> list1 = DbUtil.execute(cellValue, DbUtil.DbType.DM);
//                    List<Map<String, Object>> list2 = DbUtil.execute(cellValue, DbUtil.DbType.ORACLE);
                } catch (SQLException e) {
//                    throw e;
                    System.out.println(e.getMessage());
                }
            }

        }
    }
    //
}
